



#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "points.h"
#endif

#include <wx/wxprec.h>

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#include "wx/points.h"


#include <wx/arrimpl.cpp>
WX_DEFINE_OBJARRAY(ListPoints);



//----------------------------------------------------------------------E-+++
Point::Point(
    wxString name,
	ChartValue x,
	ChartValue y,
	ChartColor c
):	m_name(name),
	m_xval(x),
	m_yval(y),
	m_col(c) {
}



//----------------------------------------------------------------------E-+++
wxPoints::wxPoints() {
}


//----------------------------------------------------------------------E-+++
wxPoints::~wxPoints() {
	Clear();
}


void wxPoints::Add(
	const Point &p
) {
	m_vPoints.Insert( p, GetInsertPosition(p) );
}



void wxPoints::Add(
	const wxString s,
	const ChartValue x,
	const ChartValue y,
	const ChartColor c
) {
	Point p(s, x, y, c);

	Add( p );
}


void wxPoints::Clear() {
	m_vPoints.Clear();
}


//----------------------------------------------------------------------E-+++
Point wxPoints::GetPoint(
	size_t n
) const {

    size_t num = m_vPoints.GetCount();

    if ( num > n )
        return m_vPoints.Item( n );

    return Point( wxEmptyString, 0, 0 );
}


//----------------------------------------------------------------------E-+++
wxString wxPoints::GetName(
	size_t n
) const {
    size_t num = m_vPoints.GetCount();

    if ( num > n )
        return m_vPoints.Item( n ).m_name;

    return ( wxEmptyString );
}


//----------------------------------------------------------------------E-+++
ChartValue wxPoints::GetXVal(
	size_t n
) const {
    size_t num = m_vPoints.GetCount();

    if ( num > n )
        return m_vPoints.Item( n ).m_xval;

	return ( 0 );

}


//----------------------------------------------------------------------E-+++
ChartValue wxPoints::GetYVal(
	size_t n
) const {
    size_t num = m_vPoints.GetCount();

    if ( num > n )
        return m_vPoints.Item( n ).m_yval;

	return ( 0 );
}


//----------------------------------------------------------------------E-+++
ChartColor wxPoints::GetColor(
	size_t n
) const {
    size_t num = m_vPoints.GetCount();

    if ( num > n )
        return m_vPoints.Item( n ).m_col;

	return ( 0 );
}


//----------------------------------------------------------------------E-+++
size_t wxPoints::GetCount() const {
	return m_vPoints.GetCount();
}


//----------------------------------------------------------------------E-+++
ChartValue wxPoints::GetMaxX() const {
	int n = GetCount();

	if ( n > 0 )
		return m_vPoints.Item( n - 1 ).m_xval;

	return 0;
}


//----------------------------------------------------------------------E-+++
ChartValue wxPoints::GetMinX() const {
	int n = GetCount();

    if ( n > 0 )
        return m_vPoints.Item( 0 ).m_xval;

	return 0;
}


//----------------------------------------------------------------------E-+++
ChartValue wxPoints::GetMaxY() const {
    ChartValue iRes = 0;

	for ( size_t iLoop = 0;
		  iLoop < GetCount();
		  ++iLoop )
	{
		if ( GetYVal(iLoop) > iRes )
			iRes = GetYVal( iLoop );
	}

	return ( iRes );
}


//----------------------------------------------------------------------E-+++
ChartValue wxPoints::GetMinY() const {
    ChartValue iRes = 0;

	for ( size_t iLoop = 0;
		  iLoop < GetCount();
		  ++iLoop )
	{
		if ( iLoop == 0 )
			iRes = GetYVal(iLoop);
		else
			if ( GetYVal(iLoop) < iRes )
				iRes = GetYVal( iLoop );
	}

	return ( iRes );
}



size_t wxPoints::GetInsertPosition(
	const Point& p
) {

    size_t num = m_vPoints.GetCount();
    size_t loop;

    for ( loop = 0;
          loop < num;
          loop++ )
	{
		if ( m_vPoints.Item( loop ).m_xval > p.m_xval )
			break;
	}

	return ( loop );
}















